<template>
  <Modal :value="showMedicalModal" title="药店列表" footerHide width="800" @on-cancel="cancel">
    <tablePlus :columns="columns" :loading="loading" :data="dataSource" :pagination="pagination" @on-change="onchange" />
  </Modal>
</template>

<script>
import api from "@/api/commonApi";
import tablePlus from "@/components/tablePlus";
export default {
  components: {
    tablePlus
  },
  model: {
    prop: "showMedicalModal",
    event: "change"
  },
  props: {
    showMedicalModal: Boolean,
    drugId: String
  },
  data() {
    return {
      columns: [
        { type: "sum", title: "排序", width: 80, align: "center",
          render: (h, params) => {
              let sum = (this.pagination.pageNo-1)*this.pagination.pageSize + params.index +1;
              return h("span", sum);
           }
        },
        { title: "药店名称", key: "orgName", align: "center" },
        { title: "地址", key: "hosAddr", align: "center" },
        { title: "联系人", key: "linkman", width: 120,align: "center" },
        { title: "联系电话", key: "linkmanTelephone", width: 150,align: "center" }
      ],
      dataSource: [],
      loading: false,
      pagination: {
        count: null,
        pageNo: 1,
        pageSize: 10, 
      },
    };
  },
  mounted() {
  },
  methods: {
    cancel() {
      this.$emit("change", false);
    },
    findKbaoPharmacyDrugDtoPage() {
      const reqBody = {
        pageNo: this.pagination.pageNo,
        pageSize: this.pagination.pageSize,
        drugId: this.drugId,
        hospitalType: 2
      };
      this.loading = true;
      this.$axios
        .post(api.findDrugDtoPage, reqBody)
        .then(res => {
          this.loading = false;
          if (res.data.code === 1) {
            const ret = res.data.object.records;
            this.dataSource = ret || [];
            this.pagination.count = res.data.object.total;
            if (!ret || !ret.length) {
            }
          } else {
            this.$Message.error("请求异常");
            return false;
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    onchange(pagination) {
        this.pagination = {...pagination};
        this.findKbaoPharmacyDrugDtoPage();
    }
  },
  watch: {
    showMedicalModal(n) {
      if (n) {
        this.pagination.pageNo = 1;
        this.findKbaoPharmacyDrugDtoPage();
      }
    }
  }
};
</script>

<style>
.page {
    width: 100%;
    margin: 10px auto;
    text-align: center;
}
</style>